package etm.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import upc.condominio.modelo.ConceptoPago;
import upc.condominio.util.ConexionBD;
import etm.excepcion.DAOExcepcion;

public class ConceptoPagoDAO extends BaseDAO {

	public Collection<ConceptoPago> listar() throws DAOExcepcion {
	//	System.out.println("ConceptoPagoDAO: listar()");
		Collection<ConceptoPago> c = new ArrayList<ConceptoPago>();
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		ConceptoPago vo = null;
		try {
			con = ConexionBD.obtenerConexion();
			String query = "SELECT idConceptoPago,descripcion from ConceptoPago";
			stmt = con.prepareStatement(query);
			rs = stmt.executeQuery();
			while (rs.next()) {
				vo = new ConceptoPago();				
				vo.setIdConcepto(rs.getInt("idConceptoPago"));
				vo.setDescripcion(rs.getString("descripcion"));
				
				c.add(vo);
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
		return c;
	}
}